import random
import time
import unittest
import ddt

from Base.BaseSetting import TestData_dir
from Business.Mangement_Sun import HumanMangement, Administration, System_Management

@ddt.ddt
class TestManagement(unittest.TestCase):
    def setUp(self) -> None:
        self.run1= HumanMangement()
        self.run2= Administration()
        self.run3 = System_Management()


    @ ddt.file_data(TestData_dir+'management.json')
    def test_HumanMangement(self,**kwargs):
        """查看新增员工是否成功"""
        author = '孙冉'
        module = '人事管理'
        entry_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
        tel = random.randint(10000000000, 19999999999)
        work_id = 'WNCD' + str(random.randint(200, 999))
        result,status_code,res= self.run1.create_staff(kwargs.get('region_id'),kwargs.get('department_id'),kwargs.get('position'),kwargs.get('name'),kwargs.get('sex'),entry_time, tel,work_id)
        self.assertEqual(result,'success')

    def test_HumanMangement_0003(self):
        """查询员工为张丹的信息"""
        author = '孙冉'
        module = '人事管理'
        query_info = self.run1.query_staff('张丹')
        self.assertEqual(query_info[0][0],'张丹')


    barcode1 = '1' + str(int(time.time()))
    barcode2 = '2' + str(int(time.time()))
    barcode3 = '3' + str(int(time.time()))

    name = '0'+str(random.randint(1,4))
    type = '0'+str(random.randint(1,15))
    price = str(random.randint(1000,9999))
    time = time.strftime('%Y-%m-%d',time.localtime(time.time()))
    owner = '0'+str(random.randint(1,2))
    data = [{'name':name,'type':type,'barcode': barcode1,'price':price,'time':time,'owner':owner},{'name':name,'type':type,'barcode':barcode2,'price':price,'time':time,'owner':owner},{'name':name,'type':type,'barcode':barcode3,'price':price,'time':time,'owner':owner}]
    @ ddt.data(*data)
    @ ddt.unpack
    def test_Administration(self,**kwargs):
        """新增采购信息是否成功"""
        author = '孙冉'
        module = '行政综合'
        actual_res = self.run2.purchase(kwargs.get('name'),kwargs.get('type'),kwargs.get('barcode'),kwargs.get('price'),kwargs.get('time'),kwargs.get('owner'))

        self.assertEqual(actual_res[0],'success')


    def test_Administration_0003(self):
        """修改员工张丹的个人信息"""
        author = '孙冉'
        module = '行政综合'
        actual_res = self.run2.queryinfo()
        self.assertTrue('成都',actual_res[0])

    def test_System_Management(self):
        """修改员工张丹的个人信息"""
        author = '孙冉'
        module = '行政综合'

        result = self.run3.modifyinfo('张丹')

        des  = '精灵搞怪的活泼姑娘'
        actual_res = self.run3.modifysave(result,des)
        self.assertEqual(actual_res[0], '修改成功')

if __name__ == '__main__':
    unittest.main()



